#!/usr/bin/env python

from smtplib import SMTP
from poplib import POP3
from time import sleep

SMTPSVR = 'smtp.qq.com'
POP3SVR = 'pop.qq.com'

who = '316615621@qq.com'
origBody = '''\
From: %(who)s
To: %(who)s
Subject: test msg

Hello World!
''' % {'who': who}

sendSvr = SMTP(SMTPSVR,'316615621@qq.com','dongzi10131993')
sendSvr.set_debuglevel(1)
errs = sendSvr.sendmail(who, [who], origBody)
sendSvr.quit()
assert len(errs) == 0, errs
sleep(10)    # wait for mail to be delivered

recvSvr = POP3(POP3SVR)
recvSvr.user('316615621@qq.com')
recvSvr.pass_('dongzi10131993')
rsp, msg, siz = recvSvr.retr(recvSvr.stat()[0])
# strip headers and compare to orig msg
sep = msg.index('')
recvBody = msg[sep+1:]
assert origBody == recvBody # assert identical
